package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.AccountBean;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.MyBusBean;
import com.mz.ozy.mvp.model.MeModel;
import com.mz.ozy.mvp.view.MyBusContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class MyBusPresenter extends BasePresenterImpl<MyBusContract.View> implements MyBusContract.Presenter {

    private MeModel mModel;


    public MyBusPresenter() {
        mModel = new MeModel();
    }

    @Override
    public void upAccountHeader(Context context) {
        mModel.getAccountInfo(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<AccountBean>(mView) {
                    @Override
                    public void onSuccesss(AccountBean bean) {
                        mView.getAccountSuccess(bean);
                    }
                });
    }

    @Override
    public void getMeInfo(Activity activity) {
        mModel.getMeInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MeBean>(mView) {
                    @Override
                    public void onSuccesss(MeBean bean) {
                        mView.getgetMeInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void getInfo(Activity activity) {
        mModel.getBusInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MyBusBean>(mView) {
                    @Override
                    public void onSuccesss(MyBusBean bean) {
                        mView.getInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void upload(Context context, String type, String name) {
        mModel.getUpBusInfo(context, type, name)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.uploadSuccess(bean);
                    }
                });
    }
}
